package com.n9.qq.android.login.tlv;

import com.n9.qq.util.Util;

import java.util.Objects;

/**
 * @author ice
 * @since 2019/2/12 14:18
 */
public class Tlv0147 extends BaseTlv {

    public Tlv0147() {
        this.cmd = 0x0147;
    }

    /**
     * @param var1          final 0x00000010
     * @param appVersion    app版本号 3.7.1
     * @param pkgSign       final pkgSign
     * @return
     */
    public byte[] getData(long var1, byte[] appVersion, byte[] pkgSign) {
        if (Objects.isNull(appVersion)) {
            appVersion = new byte[0];
        }
        if (Objects.isNull(pkgSign)) {
            pkgSign = new byte[0];
        }

        final int appVersionLen = appVersion.length;
        final int pkgSignLen = pkgSign.length;
        byte[] data = new byte[4 + 2 + appVersionLen + 2 + pkgSignLen];
        int index = 0;

        Util.int64_to_buf32(data, index, var1);
        index += 4;

        Util.int16_to_buf(data, index, appVersionLen);
        index += 2;
        System.arraycopy(appVersion, 0, data, index, appVersionLen);
        index += appVersionLen;

        Util.int16_to_buf(data, index, pkgSignLen);
        index += 2;
        System.arraycopy(pkgSign, 0, data, index, pkgSignLen);
        return this.getBufData(data);
    }
}
